package logic

import (
	"camera/B/Rpc/camera"
	"camera/B/Rpc/internal/svc"
	"camera/B/Rpc/model/mysql"
	"context"
	"fmt"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *camera.GoodAddRequest) (*camera.GoodAddResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{
		UserId:    1,
		GoodTitle: in.GoodTitle,
		GoodStock: int(in.GoodStock),
		GoodImage: in.GoodImage,
		GoodPrice: float64(in.GoodPrice),
		GoodLike:  int(in.GoodLike),
		Status:    int(in.Status),
	}
	err := g.Create()
	if err != nil {
		return nil, fmt.Errorf("添加失败")
	}
	return &camera.GoodAddResponse{
		Success: true,
	}, nil
}
